#include "CGame.h"
//random_shuffle c++
//for_each
//find
//remove
CPlayer *Player;
CGame::CGame()
{
};
CGame::~CGame()
{
};
void CGame::Generate(int sx,int sy,int ox,int oy) //0=up 1=down 2=left 3=right
{
  int m[16][5];
  bool more;
  int i,j,k,l,x,y;
  int d1,d2;
  char b[255];
  CObject *o;
  int color;
  int wallcolor,wcolor;
  
  for(i=0;i<80;i++)//Boring stuff.
    for(j=0;j<25;j++)
      if(i==0||j==0||i==79||j==24)
	{
	  m_Room->m_Map[i][j][0] = '.';
	  m_Room->m_Map[i][j][1] = 0;
	};
  for(i=0;i<80;i++)
    for(j=0;j<25;j++)
      {
	m_Room->m_Map[i][j][0] = '.';
	m_Room->m_Map[i][j][1] = 0;
      };
  for(i=0;i<16;i++)//Initialize maze
    for(j=0;j<5;j++)
      m[i][j] = -1;
  m[rand()%(sx-1)][rand()%(sy-1)] = 0;
  while(1==1)//Generate a maze using hunt and kill.
    {
      more = false;
      i = rand()%sx;
      j = rand()%sy;
      if(j>0&&m[i][j]==-1&&m[i][j-1]!=-1)
	m[i][j] = 0;
      if(j<4&&m[i][j]==-1&&m[i][j+1]!=-1)
	m[i][j] = 1;
      if(i>0&&m[i][j]==-1&&m[i-1][j]!=-1)
	m[i][j] = 2;
      if(i<15&&m[i][j]==-1&&m[i+1][j]!=-1)
	m[i][j] = 3;
      for(i=0;i<sx;i++)
	for(j=0;j<sy;j++)
	  if(m[i][j]==-1)
	    more = true;
      /*for(i=0;i<sx;i++)//Display the maze to make sure there are no errors.
	for(j=0;j<sy;j++)
	switch(m[i][j])
	{
	case -1:
	mvaddch(j, i, 'X');
	break;
	case 0:
	mvaddch(j, i, '^');
	break;
	case 1:
	mvaddch(j, i, 'v');
	break;
	case 2:
	mvaddch(j, i, '<');
	break;
	case 3:
	mvaddch(j, i, '>');
	break;
	};
	refresh();*/
      
      if(!more)
	break;
    };
  //Pause for display
  for(i=0;i<sx;i++)//Render the maze onto the actual map in 5x5 rooms
    for(j=0;j<sy;j++)
      {
	d1 = rand()%100;
	d2 = rand()%100;
	color=rand()%8;
	wallcolor=rand()%10;
	wcolor=rand()%8;
	for(k=0;k<5;k++)
	  for(l=0;l<5;l++)
	    {
	      m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '.';
	      m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 0;
	      
	      if(k==0&&(i==0||(m[i][j]!=2&&m[i-1][j]!=3)))//Left wall or door
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '|';
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		}
	      else if(k==0&&(d1<32||(i==1&&m_Room==m_Rooms[1])))//Decide if we should put a door
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '|'; 
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		  if(l==4)//Place a hole in the wall for the door behind us.
		    {
		      x = ox+(i*5)+k;
		      y = oy+(j*5)+l-(1+(rand()%3));
		      m_Room->m_Map[x][y][0] = '.';
		      m_Room->m_Map[x][y][1] = 0;
		      o = new CDoor(x,y);
		      m_Room->m_Objects.push_back(o);
		    };
		};
	      if(l==0&&(j==0||(m[i][j]!=0&&m[i][j-1]!=1)))//Top wall or door
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '-';
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		}
	      else if(l==0&&(d2<51||(j==1&&m_Room==(CRoom *)m_Rooms[1])))//Behold the golden ratio.
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '-'; 
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		  if(k==4)
		    {
		      x = ox+(i*5)+k-(1+(rand()%3));
		      y = oy+(j*5)+l;
		      m_Room->m_Map[x][y][0] = '.';
		      m_Room->m_Map[x][y][1] = 0;
		      o = new CDoor(x,y);
		      m_Room->m_Objects.push_back(o);
		    };
		};
	      
	      if(k==4&&i==sx-1)//Exceptions at bottom and right wall of map
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '|'; 
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		}
	      if(l==4&&j==sy-1)
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '-';
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		};				
	      if(k==0&&l==0)
		{
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] = '-';
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][1] = 1;
		};			
	      if(k==4&&wallcolor==0&&i!=sx-1)
		if(color!=2)
		  m_Room->m_Map[ox+(i*5)+k+1][oy+(j*5)+l][3] = color;
		else
		  m_Room->m_Map[ox+(i*5)+k+1][oy+(j*5)+l][3] = rand()%8;
	      if(l==4&&wallcolor==0&&j!=sy-1)
		if(color!=2)
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l+1][3] = color;
		else
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l+1][3] = rand()%8;
	      if(m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][0] =='.'||wallcolor==0)
		if(color!=2)
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][3] = color;
		else
		  m_Room->m_Map[ox+(i*5)+k][oy+(j*5)+l][3] = rand()%8;
	    };
      };
  o = new CStairs(true);
  o->m_X = ox+(rand()%((sx-1)*5))+1;
  o->m_Y = oy+(rand()%((sy-1)*5))+1;
  while(m_Room->m_Map[o->m_X][o->m_Y][1]==1)
    {
      o->m_X = ox+(rand()%((sx-1)*5))+1;
      o->m_Y = oy+(rand()%((sy-1)*5))+1;
    };
  m_Room->m_Objects.push_back(o);
  if(m_Room!=m_Rooms[0])//Is this the bottom floor?
    {
      o = new CStairs(false);
      o->m_X = ox+(rand()%((sx-1)*5))+1;
      o->m_Y = oy+(rand()%((sy-1)*5))+1;
      while(m_Room->m_Map[o->m_X][o->m_Y][1]==1)
	{
	  o->m_X = ox+(rand()%((sx-1)*5))+1;
	  o->m_Y = oy+(rand()%((sy-1)*5))+1;
	};
      m_Room->m_Objects.push_back(o);
      
    };
  if(m_Room==m_Rooms[33])
    {
      o = new CLaundry();
      m_Room->m_Objects.push_back(o);
    };
  if(m_Room==m_Rooms[1])
    {//Create first floor.
      i = ((rand()%4)*5)+(rand()%3);
      x = 20;
      y = 3+1+i;
      m_Room->m_Map[x][y][0] = '.';
      m_Room->m_Map[x][y][1] = 0;
      o = new CDoor(x,y);
      m_Room->m_Objects.push_back(o);//Backyard door.
      
      i = ((rand()%4)*5)+(rand()%3);
      x = 64;
      y = 4+i;
      m_Room->m_Map[x][y][0] = '.';
      m_Room->m_Map[x][y][1] = 0;
      o = new CDoor(x,y);
      m_Room->m_Objects.push_back(o);//Front door
      
      //Starting items:
      Spawn("Weapon 1",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Armor 1",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Food",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Food",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Food",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Food",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Water",ox+1+(rand()%4),oy+1+(rand()%4));
      Spawn("Water",ox+1+(rand()%4),oy+1+(rand()%4));
      
      for(i=0;i<80;i++)//Grass
	for(j=0;j<25;j++)
	  if(i<ox||j<oy||i>ox+(sx*5)-1||j>oy+(sy*5)-1)
	    if((rand()%2==0))
	      {
		m_Room->m_Map[i][j][0] = '\'';
		m_Room->m_Map[i][j][3] = 5;
	      }
	    else
	      m_Room->m_Map[i][j][3] = 4;
      for(i=5;i<20;i++)//Backyard fence
	for(j=3;j<23;j++)
	  {
	    if(i==5&&j==3)
	      m_Room->m_Map[i][j][0] = '*';
	    if(i==5&&j!=3)
	      m_Room->m_Map[i][j][0] = '|';
	    if(i!=5&&j==3)
	      m_Room->m_Map[i][j][0] = '-';
	    
	    if((i==5&&j==22)||(i==19&&j==3)||(i==19&&j==22))
	      m_Room->m_Map[i][j][0] = '*';
	    
	    if(i!=5&&j==22&&i!=19)
	      m_Room->m_Map[i][j][0] = '-';
	    if(i==5||j==22||i==19||j==3)
	    m_Room->m_Map[i][j][3]=1;
	  };
      for(i=6;i<19;i++)//Garden
	for(j=4;j<7;j++)
	  if(rand()%3!=0)
	    m_Room->m_Map[i][j][0] = '%';
      x = 0;
      for(i=7;i<18;i++)//Trees
	for(j=9;j<21;j++)
	  if(rand()%30==0)
	    {
	      Spawn("Trees",i,j);
	      x = 1;
	    };
      if(x==0)
	for(i=7;i<18;i++)//If no trees were drawn, draw a garden.
	  for(j=9;j<21;j++)
	    if(rand()%4!=0)
	      m_Room->m_Map[i][j][0] = 11;
	    else
	      {
		if(rand()%15==0)
		  {
		    m_Room->m_Map[i][j][0] = '%';
		    m_Room->m_Map[i][j][1] = 1;
		  };
	      };
      
    };
  j = (10+(rand()%(10+(m_Room->m_RoomNum/3))))+(m_Room->m_RoomNum/3);
  for(i=0;i<j;i++)
    {
      x = ox+1+(rand()%((sx-1)*5));
      y = oy+1+(rand()%((sy-1)*5));
      if(m_Room==m_Rooms[1])
	{
	  while(x<ox+1+6&&y<oy+1+6)
	    {
	      x = ox+1+(rand()%((sx-1)*5));
	      y = oy+1+(rand()%((sy-1)*5));
	    };
	};
      d1=0;
      for(k=0;k<m_Room->m_Objects.size();k++)
	if((((CObject *)m_Room->m_Objects[k])->m_X==x&&((CObject *)m_Room->m_Objects[k])->m_Y==y)||m_Room->m_Map[x][y][1]==1)
	  d1=1;
      if(d1==0)
	{
	  if((rand()%30)==0)
	    sprintf(b,"Enemy %d",m_Room->m_RoomNum<3?1:((m_Room->m_RoomNum/3))+1);
	  else
	    sprintf(b,"Enemy %d",m_Room->m_RoomNum<3?1:((m_Room->m_RoomNum/3)));
	  Spawn(b,x,y);//SpawnObject(rand()%(m_MasterObjects.GetLength()),x,y);
	}
      else
	i--;
    };
  j = 2+(rand()%4);
  for(i=0;i<j;i++)
    {
      x = ox+1+(rand()%((sx-1)*5));
      y = oy+1+(rand()%((sy-1)*5));
      d1=0;
      for(k=0;k<m_Room->m_Objects.size();k++)
	if((((CObject *)m_Room->m_Objects[k])->m_X==x&&((CObject *)m_Room->m_Objects[k])->m_Y==y)||m_Room->m_Map[x][y][1]==1)
	  d1=1;
      if(d1==0)
	Spawn("Food",x,y);//SpawnObject(rand()%(m_MasterObjects.GetLength()),x,y);
      else
	i--;
    };
  j = 1+(rand()%4);
  for(i=0;i<j;i++)
    {
      x = ox+1+(rand()%((sx-1)*5));
      y = oy+1+(rand()%((sy-1)*5));
      d1=0;
      for(k=0;k<m_Room->m_Objects.size();k++)
	if((((CObject *)m_Room->m_Objects[k])->m_X==x&&((CObject *)m_Room->m_Objects[k])->m_Y==y)||m_Room->m_Map[x][y][1]==1)
	  d1=1;
      if(d1==0)
	Spawn("Water",x,y);//SpawnObject(rand()%(m_MasterObjects.GetLength()),x,y);
      else
	i--;
    };
  j = 3+(rand()%10);
  for(i=0;i<j;i++)
    {
      x = ox+1+(rand()%((sx-1)*5));
      y = oy+1+(rand()%((sy-1)*5));
      d1=0;
      for(k=0;k<m_Room->m_Objects.size();k++)
	if((((CObject *)m_Room->m_Objects[k])->m_X==x&&((CObject *)m_Room->m_Objects[k])->m_Y==y)||m_Room->m_Map[x][y][1]==1)
	  d1=1;
      if(d1==0)
	{
	  if((rand()%6)==0)
	    sprintf(b,"Item %d",((m_Room->m_RoomNum/3)-1)+1);
	  else
	    sprintf(b,"Item %d",((m_Room->m_RoomNum/3)-1));
	  if(i==0)
	    sprintf(b,"Weapon %d",((m_Room->m_RoomNum/3)+1));
	  if(i==1)
	    sprintf(b,"Armor %d",((m_Room->m_RoomNum/3)+1));
	  Spawn(b,x,y);//SpawnObject(rand()%(m_MasterObjects.GetLength()),x,y);
	}
      else
	i--;
    };
};
/*void CGame::SpawnObject(int n,int x,int y)
  {
  CEngine *e;
  e = (CEngine *)GetEngine();
  ((CObject *)e->m_Game.m_MasterObjects[n])->SpawnSelf(x,y);
  };*/
CObject *CGame::GetPlayer()
{
  return Player;
};
CObject *CGame::GetType(int t)
{
	int i,j;
	j = m_Room->m_Objects.size();
	for(i=0;i<j;i++)
		if(((CObject *)m_Room->m_Objects[i])->GetType()==t)
			return (CObject *)m_Room->m_Objects[i];
};
void CGame::Load()
{
	int i;
	LoadObjects();
	for(i=-25;i<25;i++)
	  m_Room = new CRoom(i);
	m_Room = m_Rooms[0];
	Generate(16,5,0,0);
	m_Room = m_Rooms[1];
	m_Room->m_Objects.push_back(new CPlayer());
	Generate(9,4,20,3);
	m_Room = m_Rooms[2];
	Generate(9,4,20,3);
	m_Room = m_Rooms[3];
	Generate(10,5,20,0);
	m_Room = m_Rooms[4];
	Generate(12,5,20,0);
	m_Room = m_Rooms[5];
	Generate(12,5,20,0);
	m_Room = m_Rooms[6];
	Generate(12,5,20,0);
	m_Room = m_Rooms[7];
	Generate(16,5,0,0);
	for(i=-25;i<25;i++)
	{
	  m_Room = m_Rooms[i];
	  if(m_Room!=NULL&&(i<0||i>7))
	    Generate(16,5,0,0);
	};
	m_Room = new CRoom(1337);
	m_Room = m_Rooms[1];
	Title();
};
void CGame::LoadObjects()
{
  CObject *o;
  //1-3 Beginning, 4-5 - 2, 6 - 3, 7-8 - 4, 9-10 - 5

  AddGroup("Enemy 1","","",new CEnemy("a white rabbit","gnaws",1,100.0f,100.0f,100,100,100,100,'r'));
  
  AddGroup("Enemy 1","","",new CEnemy("clock","bites",2,100.0f,100.0f,100,100,100,100,'c'));
  AddGroup("Enemy 1","","",new CEnemy("ants","crawl on",3,100.0f,100.0f,100,100,100,100,'a'));
  AddGroup("Enemy 1","","",new CEnemy("coworker","hits",2,100.0f,100.0f,100,100,100,100,'w'));
  AddGroup("Enemy 1","","",new CEnemy("crawling toaster","burns",2,100.0f,100.0f,100,100,100,100,'t'));
  AddGroup("Enemy 1","","",new CEnemy("lettuce","bites",1,100.0f,100.0f,100,100,100,100,'l'));
  AddGroup("Enemy 1","","",new CEnemy("a square","bites",2,100.0f,100.0f,100,100,100,100,'s'));
  AddGroup("Enemy 1","","",new CEnemy("a circle","bites",2,100.0f,100.0f,100,100,100,100,'c'));
  AddGroup("Enemy 1","","",new CEnemy("a triangle","bites",2,100.0f,100.0f,100,100,100,100,'t'));
  AddGroup("Enemy 1","","",new CEnemy("a piece of paper","cuts",2,100.0f,100.0f,100,100,100,100,'p'));
  
  AddGroup("Enemy 2","","",new CEnemy("walking table","hits",5,100,100,100,100,100,100,'T'));
  AddGroup("Enemy 2","","",new CEnemy("walking chair","bites",5,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 2","","",new CEnemy("walking fridge","hits",5,100,100,100,100,100,100,'F'));
  AddGroup("Enemy 2","","",new CEnemy("a cat","annoys",5,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 2","","",new CEnemy("your friend","hurts",5,100,100,100,100,100,100,'f'));
  AddGroup("Enemy 2","","",new CEnemy("paper plane","flies into",5,100,100,100,100,100,100,'p'));
  
  AddGroup("Enemy 3","","",new CEnemy("walking couch","bites",10,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 3","","",new CEnemy("salesman","sells",10,100,100,100,100,100,100,'S'));
  AddGroup("Enemy 3","","",new CEnemy("bartender","hits",10,100,100,100,100,100,100,'B'));
  AddGroup("Enemy 3","","",new CEnemy("lawyer","sues",10,100,100,100,100,100,100,'L'));
  AddGroup("Enemy 3","","",new CEnemy("dog","bites",10,100,100,100,100,100,100,'d'));
  AddGroup("Enemy 3","","",new CEnemy("policeman","shoots",10,100,100,100,100,100,100,'p'));
  AddGroup("Enemy 3","","",new CEnemy("cow","grazes",10,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 3","","",new CEnemy("flying doll","strangles",10,100,100,100,100,100,100,'d'));
  AddGroup("Enemy 3","","",new CEnemy("walking salt shaker","hurts",10,100,100,100,100,100,100,'s'));
  AddGroup("Enemy 3","","",new CEnemy("piggy bank","hits",10,100,100,100,100,100,100,'b'));
  
  AddGroup("Enemy 4","","",new CEnemy("wall with hands","grabs",15,100,100,100,100,100,100,'#'));
  AddGroup("Enemy 4","","",new CEnemy("broken glass","cuts",15,100,100,100,100,100,100,'g'));
  AddGroup("Enemy 4","","",new CEnemy("fingers","strangle",15,100,100,100,100,100,100,'f'));
  AddGroup("Enemy 4","","",new CEnemy("the common cold","sickens",15,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 4","","",new CEnemy("soldier","shoots",15,100,100,100,100,100,100,'s'));
  AddGroup("Enemy 4","","",new CEnemy("lion","bites",15,100,100,100,100,100,100,'L'));
  AddGroup("Enemy 4","","",new CEnemy("angry boss","fires",15,100,100,100,100,100,100,'B'));
  AddGroup("Enemy 4","","",new CEnemy("falling bricks","hit",15,100,100,100,100,100,100,'b'));
  AddGroup("Enemy 4","","",new CEnemy("grandfather clock","bites",15,100,100,100,100,100,100,'C'));
  
  AddGroup("Enemy 5","","",new CEnemy("lies","hurt",20,100,100,100,100,100,100,'!'));
  AddGroup("Enemy 5","","",new CEnemy("doppelganger","copies",20,100,100,100,100,100,100,'@'));
  AddGroup("Enemy 5","","",new CEnemy("living reflection","confuses",20,100,100,100,100,100,100,'*'));
  AddGroup("Enemy 5","","",new CEnemy("robber","shoots",20,100,100,100,100,100,100,'r'));
  AddGroup("Enemy 5","","",new CEnemy("murderer","stabs",20,100,100,100,100,100,100,'M'));
  AddGroup("Enemy 5","","",new CEnemy("television show","distracts",20,100,100,100,100,100,100,'t'));
  AddGroup("Enemy 5","","",new CEnemy("oragami swan","mezmerizes",20,100,100,100,100,100,100,'S'));
  AddGroup("Enemy 5","","",new CEnemy("sadness","depresses",20,100,100,100,100,100,100,'s'));
  
  AddGroup("Enemy 6","","",new CEnemy("programmer","programs",25,100,100,100,100,100,100,'p'));
  AddGroup("Enemy 6","","",new CEnemy("your uncle","hurts",25,100,100,100,100,100,100,'u'));
  AddGroup("Enemy 6","","",new CEnemy("your aunt","hurts",25,100,100,100,100,100,100,'a'));
  AddGroup("Enemy 6","","",new CEnemy("your mother","hurts",25,100,100,100,100,100,100,'M'));
  AddGroup("Enemy 6","","",new CEnemy("your father","hurts",25,100,100,100,100,100,100,'F'));
  AddGroup("Enemy 6","","",new CEnemy("speeding car","runs over",25,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 6","","",new CEnemy("motorcycle","runs over",25,100,100,100,100,100,100,'m'));
  AddGroup("Enemy 6","","",new CEnemy("fridge with teeth","bites",25,100,100,100,100,100,100,'F'));
  AddGroup("Enemy 6","","",new CEnemy("common cold","sickens",25,100,100,100,100,100,100,'C'));

  AddGroup("Enemy 7","","",new CEnemy("chemist","mixes",30,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 7","","",new CEnemy("bus","runs over",30,100,100,100,100,100,100,'B'));
  AddGroup("Enemy 7","","",new CEnemy("tank","shoots",30,100,100,100,100,100,100,'T'));
  AddGroup("Enemy 7","","",new CEnemy("helicopter","shoots",30,100,100,100,100,100,100,'H'));
  AddGroup("Enemy 7","","",new CEnemy("airplane","bombs",30,100,100,100,100,100,100,'A'));
  AddGroup("Enemy 7","","",new CEnemy("lawyer","sues",30,100,100,100,100,100,100,'l'));
  AddGroup("Enemy 7","","",new CEnemy("bears","claw",30,100,100,100,100,100,100,'b'));
  AddGroup("Enemy 7","","",new CEnemy("broken glass","cuts",30,100,100,100,100,100,100,'b'));
  AddGroup("Enemy 7","","",new CEnemy("chains","strangle",30,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 7","","",new CEnemy("poverty","sickens",30,100,100,100,100,100,100,'p'));
  AddGroup("Enemy 7","","",new CEnemy("machine press","crushes",30,100,100,100,100,100,100,'m'));
  AddGroup("Enemy 7","","",new CEnemy("kiln","bakes",30,100,100,100,100,100,100,'K'));
  AddGroup("Enemy 7","","",new CEnemy("living water","drowns",30,100,100,100,100,100,100,'w'));
  AddGroup("Enemy 7","","",new CEnemy("your fears","distract",30,100,100,100,100,100,100,'F'));
  AddGroup("Enemy 7","","",new CEnemy("piano","falls on",30,100,100,100,100,100,100,'P'));  
  AddGroup("Enemy 7","","",new CEnemy("corruption","hurts",30,100,100,100,100,100,100,'c'));

  AddGroup("Enemy 8","","",new CEnemy("the flu","sickens",35,100,100,100,100,100,100,'f'));
  AddGroup("Enemy 8","","",new CEnemy("food poisoning","sickens",35,100,100,100,100,100,100,'p'));
  AddGroup("Enemy 8","","",new CEnemy("salmonela","sickens",35,100,100,100,100,100,100,'s'));
  AddGroup("Enemy 8","","",new CEnemy("infection","sickens",35,100,100,100,100,100,100,'i'));
  AddGroup("Enemy 8","","",new CEnemy("disease","sickens",35,100,100,100,100,100,100,'i'));
  AddGroup("Enemy 8","","",new CEnemy("plague","sickens",35,100,100,100,100,100,100,'P'));
  AddGroup("Enemy 8","","",new CEnemy("A circular square","confuses",35,100,100,100,100,100,100,'?'));
  AddGroup("Enemy 8","","",new CEnemy("An upsidedown circle","confuses",35,100,100,100,100,100,100,'?'));
  AddGroup("Enemy 8","","",new CEnemy("A yellow curve","confuses",35,100,100,100,100,100,100,'('));
  AddGroup("Enemy 8","","",new CEnemy("A white line","confuses",35,100,100,100,100,100,100,'('));
  AddGroup("Enemy 8","","",new CEnemy("Pattern of colored dots","confuses",35,100,100,100,100,100,100,'*'));
  AddGroup("Enemy 8","","",new CEnemy("A red square","confuses",35,100,100,100,100,100,100,'*'));
  AddGroup("Enemy 8","","",new CEnemy("A blue square","confuses",35,100,100,100,100,100,100,'*'));

  AddGroup("Enemy 9","","",new CEnemy("prejudice","hates",40,100,100,100,100,100,100,'P'));
  
  AddGroup("Enemy 10","","",new CEnemy("Church","lies to",45,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 10","","",new CEnemy("White Rabbit","confuses",45,100,100,100,100,100,100,'r'));
  AddGroup("Enemy 10","","",new CEnemy("Cactus Monster","confuses",45,100,100,100,100,100,100,'C'));
  AddGroup("Enemy 10","","",new CEnemy("Mushroom Monster","confuses",45,100,100,100,100,100,100,'m'));
  AddGroup("Enemy 10","","",new CEnemy("Cultigen","confuses",45,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 10","","",new CEnemy("Hawaiian Flower","confuses",45,100,100,100,100,100,100,'h'));
  AddGroup("Enemy 10","","",new CEnemy("Frog","confuses",45,100,100,100,100,100,100,'f'));
  AddGroup("Enemy 10","","",new CEnemy("Strange Flower","confuses",45,100,100,100,100,100,100,'p'));
  AddGroup("Enemy 10","","",new CEnemy("Cancer","kills",45,100,100,100,100,100,100,'c'));
  AddGroup("Enemy 10","","",new CEnemy("Age","disables",45,100,100,100,100,100,100,'a'));
  AddGroup("Enemy 10","","",new CEnemy("Time","kills",45,100,100,100,100,100,100,'t'));
  AddGroup("Enemy 10","","",new CEnemy("Ada Lovelace","programs",45,100,100,100,100,100,100,'A'));
  AddGroup("Enemy 10","","",new CEnemy("Alan Turing","decrypts",45,100,100,100,100,100,100,'T'));
  AddGroup("Enemy 10","","",new CEnemy("Linus Torvalds","saves",45,100,100,100,100,100,100,'L'));
  AddGroup("Enemy 10","","",new CEnemy("Richard Stallman","copylefts",45,100,100,100,100,100,100,'R'));
  AddGroup("Enemy 10","","",new CEnemy("Michael Toy","designs",45,100,100,100,100,100,100,'M'));
  AddGroup("Enemy 10","","",new CEnemy("Glenn Wichman","designs",45,100,100,100,100,100,100,'G'));
  AddGroup("Enemy 10","","",new CEnemy("Ken Arnold","designs",45,100,100,100,100,100,100,'K'));
  AddGroup("Enemy 10","","",new CEnemy("Dennis Ritchie","designs",45,100,100,100,100,100,100,'D'));
  
  AddGroup("Item 1","Armor 1","",new CArmor("Socks",0,'[',1));
  AddGroup("Item 1","Armor 1","",new CArmor("Pants",1,'[',1));
  AddGroup("Item 1","Armor 1","",new CArmor("Shirt",2,'[',1));

  AddGroup("Item 2","Armor 2","",new CArmor("Shoes",0,'[',5));
  AddGroup("Item 2","Armor 2","",new CArmor("Gloves",5,'[',5));
  AddGroup("Item 2","Armor 2","",new CArmor("Sweater",2,'[',5));

  AddGroup("Item 3","Armor 3","",new CArmor("Boots",0,'[',10));
  AddGroup("Item 4","Armor 4","",new CArmor("Jeans",1,'[',15));
  AddGroup("Item 5","Armor 5","",new CArmor("Jacket",3,'[',20));
  
  AddGroup("Item 6","Armor 6","",new CArmor("Large Jacket",3,13,25));

  AddGroup("Item 7","Armor 7","",new CArmor("Raincoat",3,13,30));
  AddGroup("Item 7","Armor 7","",new CArmor("Bulletproof vest",2,13,30));
  AddGroup("Item 7","Armor 7","",new CArmor("Army helmet",4,13,30));

  AddGroup("Item 8","Armor 8","",new CArmor("Two Jackets",3,13,35));
  AddGroup("Item 8","Armor 8","",new CArmor("Comfortable shoes",0,13,35));
  AddGroup("Item 8","Armor 8","",new CArmor("Bicycle",6,13,35));

  AddGroup("Item 9","Armor 9","",new CArmor("Car",6,13,40));
  AddGroup("Item 10","Armor 10","",new CArmor("Black hat",4,13,45));
  
  AddGroup("Item 1","Weapon 1","",new CWeapon("Hammer",-1,'?',1,10,100));
  AddGroup("Item 1","Weapon 1","",new CWeapon("Knife",-1,'?',1,10,100));

  o=new CWeapon("Screw driver",-1,'?',1,10,100);
  o->AI.push_back(AI_ScrewDriver);
  AddGroup("Item 1","Weapon 1","",o);

  AddGroup("Item 1","Weapon 1","",new CWeapon("Drill",-1,'?',1,10,100));
  AddGroup("Item 1","Weapon 1","",new CWeapon("Wooden bat",-1,'?',1,10,100));
  AddGroup("Item 1","Weapon 1","",new CWeapon("Pen",-1,'?',1,10,100));//Elbereth
  AddGroup("Item 1","Weapon 1","",new CWeapon("Scissors",-1,'?',1,10,100));//Cuts paper enemies in half
  AddGroup("Item 1","Weapon 1","",new CWeapon("Blue marker",-1,'?',1,10,100));

  AddGroup("Item 2","Weapon 2","",new CWeapon("Chainsaw",-1,13,5,10,100));
  AddGroup("Item 2","Weapon 2","",new CWeapon("Metal bat",-1,13,5,10,100));
  AddGroup("Item 2","Weapon 2","",new CWeapon("Stapler",-1,13,5,10,100));
  AddGroup("Item 2","Weapon 2","",new CWeapon("Hole-puncher",-1,13,5,10,100));
  AddGroup("Item 2","Weapon 2","",new CWeapon("Hand saw",-1,13,5,10,100));
  AddGroup("Item 2","Weapon 2","",new CWeapon("Ax",-1,13,5,10,100));

  AddGroup("Item 3","Weapon 3","",new CWeapon("Shotgun",-1,13,10,10,100));
  AddGroup("Item 3","Weapon 3","",new CWeapon("Hand gun",-1,13,10,10,100));
  AddGroup("Item 3","Weapon 3","",new CWeapon("Rifle",-1,13,10,10,100));
  AddGroup("Item 3","Weapon 3","",new CWeapon("Check book",-1,13,10,10,100));
  AddGroup("Item 3","Weapon 3","",new CWeapon("Razor-wire",-1,13,10,10,100));
  
  AddGroup("Item 4","Weapon 4","",new CWeapon("Algebra",-1,13,15,10,100));
  AddGroup("Item 4","Weapon 4","",new CWeapon("Geometry",-1,13,15,10,100));
  AddGroup("Item 4","Weapon 4","",new CWeapon("Trigonometry",-1,13,15,10,100));
  AddGroup("Item 4","Weapon 4","",new CWeapon("General education",-1,13,15,10,100));
  AddGroup("Item 4","Weapon 4","",new CWeapon("Research",-1,13,15,10,100));

  AddGroup("Item 5","Weapon 5","",new CWeapon("Associates Degree",-1,13,20,10,100));
  AddGroup("Item 6","Weapon 6","",new CWeapon("Bachelors Degree",-1,13,25,10,100));
  AddGroup("Item 7","Weapon 7","",new CWeapon("Statistics",-1,13,30,10,100));
  AddGroup("Item 8","Weapon 8","",new CWeapon("Calculus",-1,13,35,10,100));
  AddGroup("Item 9","Weapon 9","",new CWeapon("AES Encryption",-1,13,40,10,100));
  AddGroup("Item 10","Weapon 10","",new CWeapon("The Truth",-1,13,45,10,100));
  
  AddGroup("Item","Food","",new CItem("Fried chicken",true,false,false,'%',true,500));
  AddGroup("Item","Food","",new CItem("Chicken soup",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Pancakes",true,false,false,'%',true,300));
  AddGroup("Item","Food","",new CItem("Waffles",true,false,false,'%',true,400));
  AddGroup("Item","Food","",new CItem("Cheese burger",true,false,false,'%',true,700));
  AddGroup("Item","Food","",new CItem("Honey",true,false,false,'%',true,300));
  AddGroup("Item","Water","",new CItem("Water",true,false,false,'%',false,100));
  AddGroup("Item","Food","",new CItem("Cereal",true,false,false,'%',true,200));
  AddGroup("Item","Water","",new CItem("Milk",true,false,false,'%',false,200));
  AddGroup("Item","Food","",new CItem("Steak",true,false,false,'%',true,900));
  AddGroup("Item","Food","",new CItem("Shrimp",true,false,false,'%',true,600));
  AddGroup("Item","Food","",new CItem("Lobster",true,false,false,'%',true,900));
  AddGroup("Item","Food","",new CItem("Fish & chips",true,false,false,'%',true,700));
  AddGroup("Item","Food","",new CItem("Birthday cake",true,false,false,'%',true,400));
  AddGroup("Item","Food","",new CItem("Chocolate pie",true,false,false,'%',true,300));
  AddGroup("Item","Food","",new CItem("Apple pie",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Ice cream",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Fudge",true,false,false,'%',true,300));
  AddGroup("Item","Food","",new CItem("Ramen",true,false,false,'%',true,100));
  AddGroup("Item","Food","Apple",new CItem("Apple",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Carmel apple",true,false,false,'%',true,250));
  AddGroup("Item","Food","",new CItem("Donut",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Chocolate",true,false,false,'%',true,300));
  AddGroup("Item","Food","",new CItem("Taco",true,false,false,'%',true,600));
  AddGroup("Item","Food","",new CItem("Pizza",true,false,false,'%',true,700));
  AddGroup("Item","Food","",new CItem("Muffin",true,false,false,'%',true,500));
  AddGroup("Item","Food","",new CItem("Cookie",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Mashed potatoes",true,false,false,'%',true,400));
  AddGroup("Item","Food","",new CItem("Turkey",true,false,false,'%',true,800));
  AddGroup("Item","Food","",new CItem("Bacon",true,false,false,'%',true,600));
  AddGroup("Item","Food","",new CItem("Sandwich",true,false,false,'%',true,600));
  AddGroup("Item","Food","",new CItem("Orange",true,false,false,'%',true,200));
  AddGroup("Item","Food","",new CItem("Ground beef",true,false,false,'%',true,500));
  AddGroup("Item","Food","",new CItem("Lasagna",true,false,false,'%',true,1000));
  AddGroup("Item","Food","",new CItem("Baked potatoe",true,false,false,'%',true,1000));
  AddGroup("Item","Food","",new CItem("Banana",true,false,false,'%',true,1000));
  AddGroup("Item","Food","",new CItem("Yogurt",true,false,false,'%',true,1000));
  AddGroup("Item","Food","",new CItem("Chichen enchiladas",true,false,false,'%',true,1000));
  AddGroup("Item","Food","",new CItem("Cheese enchiladas",true,false,false,'%',true,1000));
  

  AddGroup("Item","Water","",new CItem("Soda",true,false,false,'%',false,100));
  
  o=new CObject();
  o->AI.push_back(AI_AppleTree);
  o->Strings["Status"]["Name"]="Apple tree";
  o->m_Tile='T';
  o->m_Collide=true;
  o->m_Shown=true;
  AddGroup("Trees","","",o);

  //You eat the shrimp. Your throat swells up. You are apparently allergic to shellfish!
  //You can not breath. You can not breath. You can not breath. You die...
	/*
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("a white rabbit","hits",0,8,0,0,8,8,50,16)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("Romanticism","lies to",0,8,0,0,8,8,50,16)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("walking table","bites",0,8,0,0,8,8,50,17)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("walking couch","eats",0,8,0,0,8,8,50,18)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("clock","bites",0,8,0,0,8,8,50,18)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("fridge with teeth","bites",0,8,0,0,8,8,50,20)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("washing machine with teeth","bites",0,8,0,0,8,8,50,19)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("wall with hands","hits",0,8,0,0,8,8,50,19)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("flying table","bites",0,8,0,0,8,8,50,17)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("lies","hits",0,8,0,0,8,8,50,21)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("lawyer","sues",0,8,0,0,8,8,50,21)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("programmer","programs",0,8,0,0,8,8,50,22)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("chemist","hits",0,8,0,0,8,8,50,23)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("flying clock","hits",0,8,0,0,8,8,50,23)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("police officer","shoots",0,8,0,0,8,8,50,22)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("fire fighter","hits",0,8,0,0,8,8,50,31)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your mother","hurts",0,8,0,0,8,8,50,24)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your dad","hurts",0,8,0,0,8,8,50,25)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your brother","hurts",0,8,0,0,8,8,50,26)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("falling bricks","hits",0,8,0,0,8,8,50,26)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your sister","hurts",0,8,0,0,8,8,50,27)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("flying toaster","burns",0,8,0,0,8,8,50,28)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("crawling telephone","strangles",0,8,0,0,8,8,50,28)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("black dog","bites",0,8,0,0,8,8,50,25)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("flying books","bites",0,8,0,0,8,8,50,26)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your uncle","hurts",0,8,0,0,8,8,50,29)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your aunt","hurts",0,8,0,0,8,8,50,30)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("ants","hits",0,8,0,0,8,8,50,30)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("your friend","hits",0,8,0,0,8,8,50,31)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("a square","hits",0,8,0,0,8,8,50,27)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("a circle","hits",0,8,0,0,8,8,50,23)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("a triangle","hits",0,8,0,0,8,8,50,28)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("a snake","bites",0,8,0,0,8,8,50,27)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("television show","hurts",0,8,0,0,8,8,50,17)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("lettuce","bites",0,8,0,0,8,8,50,21)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("car","runs over",0,8,0,0,8,8,50,18)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("bus","runs over",0,8,0,0,8,8,50,26)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("angry boss","yells at",0,8,0,0,8,8,50,26)));
	m_MasterObjects.Add(AddGroup("Enemy","","",new CEnemy("coworker","hits",0,8,0,0,8,8,50,23)));
	//Rug
	//Living Vaccum.
	
	
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Shoes",0,13,2)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Sneakers",0,13,3)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Socks",0,13,1)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Shirt",1,13,3)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Coat",2,13,4)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Raincoat",2,13,5)));
	m_MasterObjects.Add(AddGroup("Item","Armor","",new CArmor("Jacket",2,13,5)));

	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Algebra",-1,13,0,7)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Statistics",-1,13,0,8)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Trigonometry",-1,13,0,10)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Associates degree",-1,13,0,5)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Hand gun",-1,13,0,5)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Sword",-1,13,1,3)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Pen",-1,13,1,3)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Shotgun",-1,13,0,20)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Bachelors degree",-1,13,0,7)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Masters degree",-1,13,0,10)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("AES Encryption",-1,13,0,3)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("DES Encryptioon",-1,13,0,10)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Piggy Bank",-1,13,1,10)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Chainsaw",-1,13,1,18)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Ax",-1,13,1,8)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Drill",-1,13,1,8)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Electric Saw",-1,13,1,10)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Hammer",-1,13,1,5)));
	m_MasterObjects.Add(AddGroup("Item","Weapon","",new CWeapon("Butcher Knife",-1,13,1,12)));
	
	m_MasterObjects.Add(AddGroup("Item","Food","",new CItem("Birthday Cake",true,false,false,13,true,200)));
	m_MasterObjects.Add(AddGroup("Item","Food","",new CItem("Cake",true,false,false,13,true,200)));
	m_MasterObjects.Add(AddGroup("Item","Food","",new CItem("Pie",true,false,false,13,true,200)));
	m_MasterObjects.Add(AddGroup("Item","Food","",new CItem("Ice Cream",true,false,false,13,true,200)));
	m_MasterObjects.Add(AddGroup("Item","Food","",new CItem("Cheese burger",true,false,false,13,true,200)));
	
	m_MasterObjects.Add(AddGroup("Item","Water","",new CItem("Soda",true,false,false,13,false,200)));
	m_MasterObjects.Add(AddGroup("Item","Water","",new CItem("Milk",true,false,false,13,false,200)));
	m_MasterObjects.Add(AddGroup("Item","Water","",new CItem("Water",true,false,false,13,false,200)));
	m_MasterObjects.Add(AddGroup("Item","Water","",new CItem("Flavored sugar water",true,false,false,13,false,200)));
	m_MasterObjects.Add(AddGroup("Item","Water","",new CItem("Chocolate milk",true,false,false,13,false,200)));
	*/
/*
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Algebra",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Statistics",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Trigonometry",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Associates degree",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Bachelors degree",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Masters degree",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("DES Encryption",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("AES Encryption",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Elliptic curve encryption",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Hand gun",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Shot gun",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Kitchen knife",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Pen",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Sword",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Piggy bank",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Pan",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Chainsaw",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Drill",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Ax",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Watch",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Saw",false,false,false,13)));
	m_MasterObjects.Add(AddGroup("test","","",new CItem("Hammer",false,false,false,13)));*/
};
CObject *CGame::AddGroup(string g,string g2,string g3,CObject *o)
{
  if(g.size()>0)
    m_MasterObjects[g].push_back(o);
  if(g2.size()>0)
    m_MasterObjects[g2].push_back(o);
  if(g3.size()>0)
    m_MasterObjects[g3].push_back(o);
  return o;
};
void CGame::Run()
{
	
};

void CGame::Title()
{
	char b[255];
	int i;
	clear();
	echo();
    mvprintw(0,0,"\\  ___ `'.                 __.....__               __  __   ___    \n");
	mvprintw(1,0," ' |--.\\  \\            .-''         '.            |  |/  `.'   `.  \n");
	mvprintw(2,0," | |    \\  ' .-,.--.  /     .-''\"'-.  `.          |   .-.  .-.   ' \n");
	mvprintw(3,0," | |     |  '|  .-. |/     /________\\   \\    __   |  |  |  |  |  | \n");
	mvprintw(4,0," | |     |  || |  | ||                  | .:--.'. |  |  |  |  |  | \n");
	mvprintw(5,0," | |     ' .'| |  | |\\    .-------------'/ |   \\ ||  |  |  |  |  | \n");
	mvprintw(6,0," | |___.' /' | |  '-  \\    '-.____...---.`\" __ | ||  |  |  |  |  | \n");
	mvprintw(7,0,"/_______.'/  | |       `.             .'  .'.''| ||__|  |__|  |__| \n");
	mvprintw(8,0,"\\_______|/   | |         `''-...... -'   / /   | |_                \n");
	mvprintw(9,0,"             |_|                         \\ \\._,\\ '/                \n");
	mvprintw(10,0,"                                          `--'  `\"                 \n");
	mvprintw(11,0,"\n");
	mvprintw(12,0,"                                       _..._                   \n");
	mvprintw(13,0,"                                    .-'_..._''.                \n");
	mvprintw(14,0,"             .                    .' .'      '.\\    .          \n");
	mvprintw(15,0,"           .'|                   / .'             .'|          \n");
	mvprintw(16,0,"          <  |                  . '             .'  |          \n");
	mvprintw(17,0,"           | |             __   | |            <    |          \n");
	mvprintw(18,0,"           | | .'''-.   .:--.'. | |             |   | ____     \n");
	mvprintw(19,0,"           | |/.'''. \\ / |   \\ |. '             |   | \\ .'     \n");
	mvprintw(20,0,"           |  /    | | `\" __ | | \\ '.          .|   |/  .      \n");
	mvprintw(21,0,"           | |     | |  .'.''| |  '. `._____.-'/|    /\\  \\     \n");
	mvprintw(22,0,"           | |     | | / /   | |_   `-.______ / |   |  \\  \\    \n");
	mvprintw(23,0,"           | '.    | '.\\ \\._,\\ '/            `  '    \\  \\  \\   \n");
	mvprintw(24,0,"           '---'   '---'`--'  `\"               '------'  '---' \n");

	refresh();
	mvprintw(0,54,"[Press space to continue.]");
	refresh();
	while((i=getch())!=' '&&i!='\n');;
	clear();
	refresh();
	mvprintw(0, 0, "DreamHack\nCreated by Bryan Strait.\nInspired by Nethack, based on Hack.\n\n\n\nWhat is your name? ");
	refresh();
	getnstr(b,255);
	curs_set(0);
	mvprintw(23,0,"You are feeling very sleepy, %s... [press space]",b);
	refresh();
	while((i=getch())!=' '&&i!='\n');;
	clear();
	mvprintw(0, 0, "You have fallen asleep. You dream that your house is very different. [more]\n\n\n\n\n\n\n\n\n\n\n\n");
	getch();
	getch();
	noecho();
};

CPlayer::CPlayer()
{
	m_Up = m_Down = m_Left = m_Right = m_Wall = false;
	m_X = 23;
	m_Y = 5;
	m_Type = 1;
	m_Health = 8;
	m_Tile = '@';
	m_Collide = true;
	m_Damage = m_Armor = m_Attack = 0;
	m_MaxDamage = 1;
	m_Health = m_MaxHealth = 100;
	strncpy(m_Name,"Player",255);
	strncpy(m_Verb,"hit",255);
	m_DrawPass = 3;
	m_HealthRate = 2;
	m_HealthProgress=0;
	m_Hunger = m_Thirst = 1400;
	m_Experience = 0;
	m_Level = 1;
	m_NextLevel = 20;
	m_Confidences["Attack"] = 0;
	m_Confidences["Defense"] = 0;
	m_Confidences["Health"] = 0;
	Player=this;
	m_Die=false;
};
CPlayer::~CPlayer()
{
	DeleteInventory();
};
void CPlayer::DeleteInventory()
{
  CItem *i;
  while(m_Inventory.size()>0)
    {
      i = (CItem *)m_Inventory[0];
      if(i!=NULL)
	delete(i);
      m_Inventory.erase(m_Inventory.begin());
    };
};
bool CPlayer::AddInvetory()
{
  int j,k;
  CObject *o=NULL;

  if(m_Inventory.size()<24)
    for(j=0;j<m_Room->m_Objects.size();j++)
      if(m_Room->m_Objects[j]->m_X==Player->m_X&&m_Room->m_Objects[j]->m_Y==Player->m_Y&&m_Room->m_Objects[j]->m_Type==6)
	{
	  o=m_Room->m_Objects[j];
	  m_Room->m_Objects.erase(m_Room->m_Objects.begin()+j);

	  for(k=0;k<m_Inventory.size();k++)
	    if(m_Inventory[k]->m_MasterNum==o->m_MasterNum)
	      {
		delete(o);
		m_Inventory[k]->m_Amount++;
		return true;
	      };
	  m_Inventory.push_back(o);
	  return true;
	};
  return false;
};
void CPlayer::DropInventory(int n)
{
  CItem *i=NULL;
  CPlayer *p;
  if(n<m_Inventory.size())
    i = (CItem *)m_Inventory[n];
  p = (CPlayer *)m_Game.GetPlayer();
  if(i==NULL)
    return;
  i->m_X = p->m_X;
  i->m_Y = p->m_Y;
  m_Room->m_Objects.push_back(i);
  m_Inventory.erase(m_Inventory.begin()+n);
};

void CPlayer::Wear(int n)
{
  CItem *i=NULL,*i2;
  int j,k;
  if(n<m_Inventory.size())
    i = (CItem *)m_Inventory[n];
  if(i==NULL)
    return;
  for(j=0;j<m_Wear.size();j++)
    {
      i2 = (CItem *)m_Wear[j];
      if(i2->m_WearType==i->m_WearType)
	TakeOff(j);
    };
  m_Wear.push_back(i);
  m_Inventory.erase(m_Inventory.begin()+n);
  i->Wear();
};
void CPlayer::TakeOff(int n)
{
  CItem *i=NULL;
  if(n<m_Wear.size())
    i = (CItem *)m_Wear[n];
  if(i==NULL)
    return;
  m_Inventory.push_back(i);
  m_Wear.erase(m_Wear.begin()+n);
  i->TakeOff();
};
void CPlayer::Use(int n)
{
  CObject *i=NULL;
  if(n<m_Inventory.size())
    i = m_Inventory[n];
  if(i==NULL)
    return;
  ((CItem *)i)->Use();
};
void CPlayer::Eat(int n)
{
	CItem *i=NULL;
	if(n<m_Inventory.size())
	  i = (CItem *)m_Inventory[n];
	if(i==NULL||!i->m_Eat)
		return;
	i->Eat();
	if(i->m_Amount>1)
		i->m_Amount--;
	else
	{
	  m_Inventory.erase(m_Inventory.begin()+n);
	  delete(i);
	};
	
};

void CPlayer::ShowConfidences()
{
  int i;
  map<string,int>::iterator it;
  clear();
  mvprintw(0,0,"Confidences:");
  i=1;
  for( it=m_Confidences.begin(); it!=m_Confidences.end(); it++)
    mvprintw(i++,1,"%s : %d\n",it->first.c_str(),it->second);
};

void CPlayer::Run()
{
	CObject *o;
	char msg[255];
	int i;

	if(m_Up&&(!CollideMap(m_X,m_Y-1)||m_Wall))
		m_Y--;
	if(m_Down&&(!CollideMap(m_X,m_Y+1)||m_Wall))
		m_Y++;
	if(m_Left&&(!CollideMap(m_X-1,m_Y)||m_Wall))
		m_X--;
	if(m_Right&&(!CollideMap(m_X+1,m_Y)||m_Wall))
		m_X++;
	i=0;
	while((o=CollideObject(i))!=NULL)
	{
		if(o->m_Collide)
		{
			if(m_Up)
				m_Y++;
			if(m_Down)
				m_Y--;
			if(m_Left)
				m_X++;
			if(m_Right)
				m_X--;
			o->Message(10);
			break;
		};
		i++;
	};
	m_Up = m_Down = m_Left = m_Right = false;
	if(m_HealthProgress>m_HealthRate)
	{
		if(m_Hunger>29&&m_Thirst>29)
			m_Health++;
		else
			m_Health--;
		m_Hunger-=1;
		m_Thirst-=1;
		m_HealthProgress=0;
	}
	else
		m_HealthProgress++;
	if(m_Health>m_MaxHealth)
		m_Health=m_MaxHealth;
	sprintf(msg,"HP: %d/%d XP: %d/%d ",m_Health,m_MaxHealth,m_Experience,m_NextLevel);
	m_GUI.AddBottom(msg);
	if(m_Hunger>30&&m_Hunger<500)
	{
		sprintf(msg,"Hungry ");
		m_GUI.AddBottom(msg);
	};
	if(m_Hunger<30)
	{
		sprintf(msg,"Starving ");
		m_GUI.AddBottom(msg);
	};
	if(m_Hunger>1500)
	{
		sprintf(msg,"Stuffed ");
		m_GUI.AddBottom(msg);
	};
	if(m_Thirst<100)
	{
		sprintf(msg,"Thirsty ");
		m_GUI.AddBottom(msg);
	};
	if(m_Thirst>3000)
		m_Thirst=3000;
	if(m_Hunger>3000)
		m_Hunger=3000;
	if(m_Experience>m_NextLevel-1)
	{
		GainLevel();
		m_Level++;
		m_Experience = 0;
		m_NextLevel=(int)((float)m_NextLevel*1.5f);
		m_MaxHealth+=2+(rand()%(2+(m_Confidences["Health"]/4)));
	};
	if(m_Health<0&&!m_Wall)
	{
		m_GUI.AddTop("You die... [press any key to continue]\n",true);
		EndGame();
	};
};

void CPlayer::Draw()
{
  mvaddch(m_Y-m_Room->m_CameraY,m_X-m_Room->m_CameraX,m_Tile);
};
void CPlayer::EndGame()
{
  m_On = false;
};

void CPlayer::Input(int e)
{
	CObject *o,*o2;
	int i;
	switch(e)
	  {
	  case KEY_UP: case '8':
	    m_Up = true;
	    break;
	  case KEY_DOWN: case '2':
	    m_Down = true;
	    break;
	  case KEY_LEFT: case '4':
	    m_Left = true;
	    break;
	  case KEY_RIGHT: case '6':
	    m_Right = true;
	    break;
	  case '1':
	    m_Down=true;m_Left=true;
	    break;
	  case '3':
	    m_Down=true;m_Right=true;
	    break;
	  case '7':
	    m_Up=true;m_Left=true;
	    break;
	  case '9':
	    m_Up=true;m_Right=true;
	    break;
	  case '>':
	  case '<':
	    o = CollideObject(0);
	    if(o!=NULL)
	      o->Message(0);
	    else if(m_Wall)
	      {
		if(e=='>')
		  o = new CStairs(false);
		else
		  o = new CStairs(true);
		o->Message(0);
		delete(o);
	      };
	    break;
	  case 'g':
	    AddInvetory();
	    break;
	  case 'i':
	    ShowInventory();
	    refresh();
	    getch();
	    break;
	  case 'E':
	    ShowWearing();
	    refresh();
	    getch();
	    break;
	  case 'W':
	    m_Wall = !m_Wall;
	    break;
	  case 'u':
	    ShowInventory();
	    mvprintw(0,0,"Use what?\n");
	    i = getch();
	    i-='a';
	    Use(i);
	    break;
	  case 'w':
	    ShowInventory();
	    mvprintw(0,0,"Wear or hold what?\n");
	    i = getch();
	    i-='a';
	    Wear(i);
	    break;
	  case 'r':
	    o = m_Game.GetPlayer();
	    if(((CPlayer *)o)->m_Hunger<29)
	      {
		mvprintw(0,0,"You are too hungry to rest.\n");
		getch();
		return;
	      };
	    
	    if(m_Game.m_SeenEnemies>0)
	      {
		mvprintw(0,0,"You can't rest with enemies nearby.\n");
		getch();
		return;
	      };
	    
	    mvprintw(0,0,"Rest for how many turns? (+1 health each turn) ");
	    echo();
	    curs_set(1);
	    scanw("%d\n",&i);
	    curs_set(0);
	    noecho();
	    ((CPlayer *)o)->m_Health+=i;
	    ((CPlayer *)o)->m_Hunger-=i;
	    ((CPlayer *)o)->m_Thirst-=(i/4);
	    break;
	  case 'e':

	    ShowInventory();
	    mvprintw(0,0,"Eat or drink what?\n");
	    i = getch();
	    i-='a';
	    Eat(i);
	    break;
	  case 'c':
	    ShowConfidences();
	    refresh();
	    getch();
	    break;
	  case 't':
	    ShowWearing();
	    mvprintw(0,0,"Take off what?\n");
	    i = getch();
	    i-='a';
	    TakeOff(i);
	    break;
	  case 'd':
	    ShowInventory();
	    mvprintw(0,0,"Drop what?\n");
	    i = getch();
	    i-='a';
	    DropInventory(i);
	    break;
	  case '?':
	    mvprintw(0,0,"Keys:\n");
	    printw(" w - Wear/Hold\n");
	    printw(" e - Eat/Drink\n");
	    printw(" u - Use\n");
	    printw(" g - Get\n");
	    printw(" i - Inventory\n");
	    printw(" E - View worn/held items\n");
	    printw(" W - \"Wizard\" mode\n");
	    printw(" q - Quit\n");
	    printw(" o - Open/Close\n");
	    printw(" d - Drop\n");
	    printw(" t - Take off\n");
	    printw(" r - Rest\n");
	    printw(" c - View confidences\n");
	    getch();
	    break;
		case 'o':
		  mvprintw(0,0,"Open or close what? (direction)\n");
		  switch(getch())
		    {
		    case KEY_UP:
		      m_Y--;
		      o = CollideObject(0);
		      if(o!=NULL)
			o->Message(1);
		      m_Y++;
					break;
		    case KEY_DOWN:
		      m_Y++;
		      o = CollideObject(0);
		      if(o!=NULL)
			o->Message(1);
		      m_Y--;
		      break;
		    case KEY_LEFT:
		      m_X--;
		      o = CollideObject(0);
		      if(o!=NULL)
			o->Message(1);
		      m_X++;
		      break;
		    case KEY_RIGHT:
		      m_X++;
		      o = CollideObject(0);
		      if(o!=NULL)
			o->Message(1);
		      m_X--;
		      break;
		    };
		  break;
	  };
};
void CPlayer::GainLevel()
{
  int i,n,s;
  map<string,int>::iterator it;
  if(m_Level!=1)
    n = 2+(rand()%3);
  else
    n = 6;
  s = 0;
  clear();
  mvprintw(0,0,"You gained a level! Press space to continue.");
  while(getch()!=' ');
  while(1==1)
    {
      
      ShowConfidences();
      mvprintw(0,0,"Distribute points to your confidences: (%d points left) (q to exit)\n",n);
      mvprintw(1+s,0,">");
      i=0;
      for(it=m_Confidences.begin();it!=m_Confidences.end();it++)
	mvprintw(1+(i++),1,"%s : %d\n",it->first.c_str(),it->second);
      i = getch();
      
      switch(i)
	{
	case KEY_UP:
	  s--;
	  break;
	case KEY_DOWN:
	  s++;
	  break;
	case KEY_LEFT:
	  break;
	case KEY_RIGHT:
	  if(n<1)
	    break;
	  it = m_Confidences.begin();
	  for(i=0;i<s;i++)
	    it++;
	  it->second+=1;
	  n--;
	  break;
	case 'q':
	  if(n<1)
	    return;
	  else
	    {
	      mvprintw(0,0,"You still have points left to distribute!\n");
	      getch();
	    };
	  break;
	};
      if(s<0)
	s=0;
      if(s>m_Confidences.size())
	s = m_Confidences.size()-1;
    };
};
void CPlayer::ShowInventory()
{
  int i;
  mvprintw(0,40,"Inventory");
  for(i=0;i<m_Inventory.size();i++)
    if(((CItem *)m_Inventory[i])->m_Amount>1)
      mvprintw(i+1,40,"%c - %d %s",i+'a',((CItem *)m_Inventory[i])->m_Amount,((CItem *)m_Inventory[i])->Name.c_str());
    else
      mvprintw(i+1,40,"%c - %s",i+'a',((CItem *)m_Inventory[i])->Name.c_str());
};
void CPlayer::ShowWearing()
{
  int i;
  mvprintw(0,40,"Wearing");
  for(i=0;i<m_Wear.size();i++)
    mvprintw(i+1,40,"%c - %s",i+'a',((CItem *)m_Wear[i])->Name.c_str());
};
void CPlayer::Message(int m)
{
};
CDoor::CDoor(int x,int y)
{
  m_Open = false;
  m_X = x;
  m_Y = y;
  m_Tile = '+';
  m_Type = 2;
  m_Clear = false;
  m_Collide = true;
  m_DrawPass = 0;
  m_Die=false;
};

void CDoor::Message(int m)
{
  if(m==1||m==10)
    m_Open = !m_Open;
  if(m_Open)
    m_Tile = '`';
  else
    m_Tile = '+';
  if(m_Open)
    m_Clear=true;
  else
    m_Clear=false;
  if(m_Open)
    m_Collide = false;
  else
    m_Collide = true;
};
CStairs::CStairs(bool d)
{
  m_Die=false;
  m_Up = d;
  if(d)
    m_Tile=m_Type=3;
  else
    m_Tile=m_Type=4;
  if(d)
    m_Tile='<';
  else
    m_Tile='>';
  m_DrawPass = 0;
};
CStairs::~CStairs()
{
};
void CStairs::Message(int m)
{
  int i;
  CObject *p,*o;
  if(m==0)
    {
      for(i=0;i<m_Room->m_Objects.size();i++)
	if(m_Room->m_Objects[i]==m_Game.GetPlayer())
	  {
	    p = m_Room->m_Objects[i];
	    m_Room->m_Objects.erase(m_Room->m_Objects.begin()+i);
	    break;
	  };
      if(m_Up)
	m_Room=m_Rooms[m_Room->m_RoomNum+1];
      else
	m_Room=m_Rooms[m_Room->m_RoomNum-1];
      m_Room->m_Objects.push_back(p);
      o=m_Up?m_Game.GetType(4):m_Game.GetType(3);
      p->m_X=o->m_X;
      p->m_Y=o->m_Y;
      mvprintw(0,0,"You go %s.\n",m_Up?"up":"down");
      getch();
    };
};


CEnemy::CEnemy()
{
  m_Damage = m_Armor = m_Attack = m_HealthProgress = 0;
  m_MaxDamage = m_Health = m_MaxHealth = 8;
  m_HealthRate = 50;
  Name = "Enemy";
  strncpy(m_Verb,"hits",255);
  m_Tile = 15;
  m_Type = 5;
  m_Collide = true;
  m_DrawPass = 2;
  m_Experience = 1+(rand()%4);
  m_Die=false;
};
	//Enemy Hp: hp = (level*10)+(0 to level). Each level enemies can increase a skill by 2.
	//Groups of enemies every 5 floors, in 5 floors the player can increase 5 levels
	//Therefore each group of enemies should be 5 levels higher than the last.
	//Experience should match up, such that the player can only get 5 levels in 5 floors.
	//XP from enemies for 5 levels needs to = what the player needs to gain 5 levels.
	//1.332 to the 5th, times starting next level XP to be exact. Each floor must have
	//an exact experience value of enemies. Each floor should spawn ((RequiredXPForPlayerLevel*0.9)/EnemyLevelAsXP) enemies
	//EnemyXP is determined by XPRequiredToGainLevelAtLevelOfEnemy/DefaultEnemyNumber
	//Damage increase per level is worth 2 points of total enemy pool. Enemy pool
	//should be (level*2) (Each level enemy can gain 2 points) (Player gets 3)
	//Each group could have enemies of levels up to 4 over the group's base level.
CEnemy::CEnemy(char *n,char *v,int l,float d,float md,float ar,float a,float mh,float hr,int t)
{
  float points;
  float total;
  Name = "Enemy";
  strncpy(m_Verb,"hits",255);
  Name = n;
  strncpy(m_Verb,v,255);
  points = l*2;
  total = d+md+ar+a+mh+hr;
  if(total!=1.0f)
    {
      d/=total;
      md/=total;
      ar/=total;
      a/=total;
      mh/=total;
      hr/=total;
    };
  m_Damage = 1+((float)d*(float)points);
  m_MaxDamage = 2+((float)md*(float)points);
  m_Armor = (ar*points);
  m_Attack = (a*points);
  m_Health = m_MaxHealth = 4+((mh*points)+(l*5));
  m_HealthRate = 70-(hr*points);
  m_Tile = t;
  m_Type = 5;
  m_Collide = true;
  m_DrawPass = 2;
  m_Die=false;
};
CEnemy::~CEnemy()
{
};

CEnemy *CEnemy::SpawnSelf(int x,int y)
{
  CEnemy *o;
  o = new CEnemy();
  o->m_X = x;
  o->m_Y = y;
  o->m_Collide = m_Collide;
  o->m_Shown = m_Shown;
  o->m_Clear = m_Clear;
  o->m_Type = m_Type;
  o->m_Tile = m_Tile;
  o->m_Damage = m_Damage;
  o->m_Armor = m_Armor;
  o->m_Attack = m_Attack;
  o->m_HealthProgress = m_HealthProgress;
  o->m_MaxDamage = m_MaxDamage;
  o->m_Health = m_Health;
  o->m_MaxHealth = m_MaxHealth;
  o->m_HealthRate = m_HealthRate;
  o->Name = Name;
  strncpy(o->m_Verb,m_Verb,255);
  m_Room->m_Objects.push_back(o);
  return o;
};

void CEnemy::Run()
{
  if(m_Health>-1)
    AI();
  else
    Die();
};
void CEnemy::Message(int m)
{
  if(m==10)
    Defend();
};

void CEnemy::AI()
{
  CPlayer *p;
  int i;
  p = (CPlayer *)m_Game.GetPlayer();
  m_HealthProgress++;
  if(m_Health<m_MaxHealth&&m_HealthProgress>m_HealthRate)
    {
      m_Health++;
      m_HealthProgress=0;
    };
  if(abs(m_X-p->m_X)>4||abs(m_Y-p->m_Y)>4)
    {
      i = rand()%4;
      if(i==0)
	Move(m_X,m_Y-1,false);
      if(i==1)
	Move(m_X,m_Y+1,false);
      if(i==2)
	Move(m_X-1,m_Y,false);
      if(i==3)
	Move(m_X+1,m_Y,false);
    }
  else
    {
      i = 0;
      if(p->m_X<m_X&&rand()%5==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X-1,m_Y,false);
	  else
	    Move(m_X+1,m_Y,false);
	  i = 1;
	};
      if(p->m_Y<m_Y&&i==0&&rand()%2==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X,m_Y-1,false);
	  else
	    Move(m_X,m_Y+1,false);
	  i = 1;
	};
      if(p->m_X>m_X&&i==0&&rand()%5==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X+1,m_Y,false);
	  else
	    Move(m_X-1,m_Y,false);
	  i = 1;
	};
      if(p->m_Y>m_Y&&i==0&&rand()%2==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X,m_Y+1,false);
	  else
	    Move(m_X,m_Y-1,false);
	  i=1;
	};
      
      
      if(p->m_X<m_X&&i==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X-1,m_Y,false);
	  else
	    Move(m_X+1,m_Y,false);
	  i = 1;
	};
      if(p->m_Y<m_Y&&i==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X,m_Y-1,false);
	  else
	    Move(m_X,m_Y+1,false);
	  i = 1;
	};
      if(p->m_X>m_X&&i==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X+1,m_Y,false);
	  else
	    Move(m_X-1,m_Y,false);
	  i = 1;
	};
      if(p->m_Y>m_Y&&i==0)
	{
	  if(m_Health>m_MaxHealth/3)
	    Move(m_X,m_Y+1,false);
	  else
	    Move(m_X,m_Y-1,false);
	  i=1;
	};
      if(i==0)
	{
	  mvprintw(0,0,"ERROR.");
	  getch();
	};
      Attack(false);
    };
};

//Damage reduction is worth twice damage resistance. Could either multiply i by attack or 15 by attack. 15 could be
//multiplied by player defence, i could be multiplied by attack. Maybe. i could be first multiplied by %attack+1.0f,
//then multiplied by ... maybe 15 is then multiplied by 1.0f+%playerdefense.  Attack is then worth 4x defense, roughly.
//Maybe attack is multiplied by defense. Have to make sure that defense doesn't grow
//toward infinity while attack only grows toward doubling. i*=(1.0f+(%attack*(1.0f-%defense)))
//This still makes defense more worthwhile than attack because 100 defense = 0 attack, versus 100 attack
//has no such correlation to defense. 0.05% attack * 0.95 = something like 0.48, so 5% defense isn't worth
// 5% attack. 0.5 * 0.5 = 0.25.  Maybe we should instead multiply 15, as it is constant instead of random.
// requiredtohit=15*(1.0f-(%attack-%defense)); if attack is 0 and defense is 100, 1.0 drops to 0.0, which
//might be unbalanced. If attack = 100 and d = 0 we increase to 30, which is infinity as far as we're concerned.
// so 100 v 0 always wins, no matter if it's attack or defense. if 50 v 50, 1.0+0, so 15, balanced.
void CEnemy::Attack(bool f)
{
  CPlayer *p;
  char msg[255];
  int i;
  float j;
  bool d;
  p = Player;
  i = abs(m_X-p->m_X);
  j = abs(m_Y-p->m_Y);
  if(i>1||j>1)
    return;
  i = (rand()%30);
  if(i==29)
    d=true;
  else
    d=false;
  //i+=m_Attack;
  //i-=p->m_Armor+(p->m_Confidences.GetConfidence("Defense")/3);
  if(i<16)
    i=0;
  j = 15.0f*(1.0f-(((float)m_Attack/100.0f)-((float)Player->m_Confidences["Defense"]/100.0f)));
  if(i>j||d)
    {
      if(m_MaxDamage-m_Damage<2)
	m_MaxDamage=m_Damage+5;
      i = m_Damage+(rand()%(int)(m_MaxDamage-m_Damage));
      if(d)
	i*=3;
      i-=p->m_Armor;
      if(i<0)
	i=0;
      if(i==0&&d)
	i = 1;
      p->m_Health-=i;
      p->Message(30);
    };
  if(i!=0)
    {
      if(!d)
	sprintf(msg,"%s %s you for %d. ",Name.c_str(),m_Verb,i);
      else
	sprintf(msg,"%s %s you for %d! ",Name.c_str(),m_Verb,i);
    }
  else
    sprintf(msg,"%s misses. ",Name.c_str());
  m_GUI.AddTop(msg,true);
};
void CEnemy::Defend()
{
  CPlayer *p;
  char msg[255];
  int i;
  float j;
  bool d;
  p = Player;
  i = (rand()%30);
  if(i==29)
    d=true;
  else
    d=false;
  //i+=p->m_Attack+(p->m_Confidences.GetConfidence("Attack")/3);
  //i-=m_Armor;
  if(i<16)
    i=0;
  j = 15.0f*(1.0f-(((float)p->m_Attack/100.0f)-((float)m_Armor/100.0f)));
  if(i>j||d)
    {
      i = p->m_Damage+(rand()%(int)(p->m_MaxDamage-p->m_Damage));
      if(d)
	i*=3;
      i-=m_Armor;
      if(i<0)
	i=0;
      if(i==0&&d)
	i = 1;
      m_Health-=i;
    };
  if(i!=0)
    {
      if(!d)
	sprintf(msg,"You %s %s for %d. ",p->m_Verb,Name.c_str(),i);
      else
	sprintf(msg,"You %s %s for %d! ",p->m_Verb,Name.c_str(),i);
    }
  else
    sprintf(msg,"You missed %s. ",Name.c_str());
  if(m_Health<0)
    {
      sprintf(msg,"You killed %s! (%d) ",Name.c_str(),i);
      p->m_Experience+=m_Experience;
      Die();
    };
  m_GUI.AddTop(msg,true);
};
void CEnemy::Move(int x,int y,bool f)
{
  CObject *o;
  int i;
  int x2,y2;
  if(CollideMap(x,y)&&!f)
    return;
  i=0;
  x2 = m_X;
  y2 = m_Y;
  m_X = x;
  m_Y = y;
  o=CollideObject(i);
  while(o!=NULL)
    {
      if(o->m_Collide)
	{
	  o->Message(30);
	  if(!f)
	    {
	      m_X = x2;
	      m_Y = y2;
	      return;
	    };
	};
      i++;
      o=CollideObject(i);
    };
};

CItem::CItem()
{
  m_Die=false;
};
CItem::CItem(char *n,bool e,bool w,bool u,int t,bool f,int fa)
{
  Name=n;
  m_Eat = e;
  m_Wear = w;
  m_Use = u;
  m_Tile = t;
  m_Type = 6;
  m_Collide = false;
  m_DrawPass = 1;
  m_WearType = 0;
  m_FoodAmount = fa;
  m_FoodType = f;
  m_MasterNum = GenerateID();
  m_Amount = 1;
  m_Die=false;
};
CItem::~CItem()
{
};

CItem *CItem::SpawnSelf(int x,int y)
{
  CItem *o;
  int i;
  o = new CItem((char *)Name.c_str(),m_Eat,m_Wear,m_Use,m_Tile,m_FoodType,m_FoodAmount);
  o->m_X = x;
  o->m_Y = y;
  o->m_Collide = m_Collide;
  o->m_Shown = m_Shown;
  o->m_Clear = m_Clear;
  o->m_Type = m_Type;
  o->m_WearType = m_WearType;
  o->m_Tile = m_Tile;
  o->m_FoodType = m_FoodType;
  o->m_FoodAmount = m_FoodAmount;
  o->m_MasterNum = m_MasterNum;
  o->m_Amount = m_Amount;
  o->Flags = Flags;
  o->Vars = Vars;
  o->Strings = Strings;
  o->AI = AI;
  o->Name=Name;

  m_Room->m_Objects.push_back(o);
  return o;
};

void CItem::Run()
{
};
void CItem::Message(int m)
{
  switch(m)
    {
    case 21:
      Eat();
      break;
    case 22:
      Wear();
      break;
    case 23:
      Use();
      break;
    };
};

void CItem::Eat()
{
  if(!m_Eat)
    return;
  if(m_FoodType)
    Player->m_Hunger+=m_FoodAmount;
  else
    Player->m_Thirst+=m_FoodAmount;
};
void CItem::Wear()
{
};
void CItem::TakeOff()
{
};
void CItem::Use()
{
  int i;
  for(i=0;i<AI.size();i++)
    AI[i](this,"use");
};

CArmor::CArmor(char *n,int w,int t,int a)
{
  Name=n;
  m_Eat = false;
  m_Wear = true;
  m_Use = false;
  m_Tile = t;
  m_Tile='[';
  m_Type = 6;
  m_Collide = false;
  m_DrawPass = 1;
  m_WearType = w;
  m_Armor = a/2;
  m_Shown = true;
  m_Amount = 1;
  m_MasterNum = GenerateID();
  m_Die=false;
};
CArmor::~CArmor()
{
};

CItem *CArmor::SpawnSelf(int x,int y)
{
  CArmor *o;
  int i;
  o = new CArmor((char *)Name.c_str(),m_WearType,m_Tile,m_Armor);
  o->m_X = x;
  o->m_Y = y;
  o->m_Collide = m_Collide;
  o->m_Shown = m_Shown;
  o->m_Clear = m_Clear;
  o->m_Type = m_Type;
  o->m_MasterNum = m_MasterNum;
  o->m_Amount = m_Amount;
  o->m_Tile=m_Tile;
  o->Flags = Flags;
  o->Vars = Vars;
  o->Strings = Strings;
  o->AI = AI;
	
  o->m_MasterNum = m_MasterNum;
  o->Name=Name;
  m_Room->m_Objects.push_back(o);

  return o;
};

void CArmor::Wear()
{
  CPlayer *p;
  p = (CPlayer *)m_Game.GetPlayer();
  p->m_Armor+=m_Armor;
};
void CArmor::TakeOff()
{
  CPlayer *p;
  p = (CPlayer *)m_Game.GetPlayer();
  p->m_Armor-=m_Armor;
  if(p->m_Armor<0)
    p->m_Armor=0;
};

CWeapon::CWeapon(char *n,int w,int t,int min,int max)
{
  Name=n;
  m_Eat = false;
  m_Wear = true;
  m_Use = false;
  m_Tile = t;
  m_Type = 6;
  m_Collide = false;
  m_DrawPass = 1;
  m_WearType = w;
  m_Shown = true;
  m_Tile = '/';
  m_MinDamage = min;
  m_MaxDamage = max;
  m_Amount = 1;
  m_MasterNum = GenerateID();
  m_Die=false;
};
CWeapon::CWeapon(char *n,int w,int t,int l,float min,float max)
{
  float points,total;
  Name=n;
  m_Eat = false;
  m_Wear = true;
  m_Use = false;
  m_Tile = t;
  m_Type = 6;
  m_Collide = false;
  m_DrawPass = 1;
  m_WearType = w;
  m_Shown = true;
  m_Tile = '/';
  m_Amount = 1;
  points = l;
  total = min+max;
  if(total!=1.0)
    {
      min/=total;
      max/=total;
    };
  m_MinDamage = 1+(points*min);
  m_MaxDamage = 8+(points*max);
  m_MasterNum = GenerateID();
  m_Die=false;
	
};
CWeapon::~CWeapon()
{
};

CItem *CWeapon::SpawnSelf(int x,int y)
{
  CWeapon *o;
  int i;
  o = new CWeapon((char *)Name.c_str(),m_WearType,m_Tile,m_MinDamage,m_MaxDamage);
  o->m_X = x;
  o->m_Y = y;
  o->m_Collide = m_Collide;
  o->m_Shown = m_Shown;
  o->m_Clear = m_Clear;
  o->m_Type = m_Type;
  o->m_Tile = m_Tile;
  o->Flags = Flags;
  o->Vars = Vars;
  o->Strings = Strings;
  o->AI = AI;
  o->Name=Name;
  o->m_MasterNum = m_MasterNum;
  o->m_Amount = m_Amount;
  m_Room->m_Objects.push_back(o);
  return o;
};

void CWeapon::Wear()
{
  CPlayer *p;
  p = (CPlayer *)m_Game.GetPlayer();
  p->m_Damage+=m_MinDamage;
  p->m_MaxDamage+=m_MaxDamage;
};
void CWeapon::TakeOff()
{
  CPlayer *p;
  p = (CPlayer *)m_Game.GetPlayer();
  p->m_Damage-=m_MinDamage;
  p->m_MaxDamage-=m_MaxDamage;
  if(p->m_Damage<0)
    p->m_Damage=0;
  if(p->m_MaxDamage<p->m_Damage-1)
    p->m_MaxDamage=p->m_Damage+1;
};

CLaundry::CLaundry()
{
  Name="+Laundry+";
  m_Type = 6;
  m_Collide = false;
  m_DrawPass = 1;
  m_WearType = 0;
  m_FoodAmount = 0;
  m_FoodType = false;
	
  m_Wear = false;
  m_Use = true;
  m_Eat = false;
  m_Tile = '&';
  m_Clear = true;
  m_X = 1;
  m_Y = 1;
  m_Amount = 1;
  m_MasterNum = -1;
  m_Die=false;
};
CLaundry::~CLaundry()
{
};
void CLaundry::Use()
{
  mvprintw(0,0,"You win! No, really.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  getch();
  getch();
  getch();
  getch();
  m_On = false;
};

CObject *AI_AppleTree(CObject *o,string m)
{
  int i;
  if(o==NULL)
    return o;
  if(m=="Message10")
    {
      m_GUI.AddTop("A nice looking apple tree.",false);
    };
  if(m=="init")
    {
      o->Vars["dropped apples"]=false;
      o->Vars["apple drop wait"]=0;
    };
  if(Player->m_Hunger<600)
    {
      for(i=0;i<Player->m_Inventory.size();i++)
	if(((CItem *)Player->m_Inventory[i])->m_Eat==true)
	  return o;
      if(o->Flags["dropped apples"]==false)
	{
	  Spawn("Apple",o->m_X,o->m_Y+1);
	  Spawn("Apple",o->m_X+1,o->m_Y);
	  Spawn("Apple",o->m_X-1,o->m_Y);
	  o->Flags["dropped apples"]=true;
	  o->Vars["apple drop wait"]=TotalTurns+1000;
	};
      if(o->Vars["apple drop wait"]<TotalTurns)
	    o->Flags["dropped apples"]=false;
    };

  return o;
};
CObject *AI_ScrewDriver(CObject *o,string m)
{
  int i,x,y;
  if(o==NULL)
    return o;
  if(m=="use")
    {
      mvprintw(0,0,"Which direction?\n");
      refresh();
      x=Player->m_X;
      y=Player->m_Y;
      switch(getch())
	{
	case KEY_UP:
	  y--;
	  break;
	case KEY_DOWN:
	  y++;
	  break;
	case KEY_LEFT:
	  x--;
	  break;
	case KEY_RIGHT:
	  x++;
	  break;
	};
      for(i=0;i<m_Room->m_Objects.size();i++)
	if(m_Room->m_Objects[i]->m_X==x&&m_Room->m_Objects[i]->m_Y==y)
	  {
	    m_Room->m_Objects[i]->Message("unscrew");
	  };
    };
  return o;
};
